<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<p class="aui-gutter-column-sm">
    {{title}}
    <i lv-icon="aui-icon-help" lv-tooltip="{{'protection_file_level_tip_label' | i18n}}" lvTooltipTheme="light"
        lvTooltipPosition="right" lvColorState='true'></i>
</p>
<lv-alert lvType="info" *ngIf="selectedTotal > 1000">
    {{'protection_file_level_max_file_label' | i18n}}
</lv-alert>
<lv-alert lvType="info" *ngIf="searchMax">
    {{'protection_file_level_max_search_label' | i18n}}
</lv-alert>
<lv-form class="aui-gutter-column-md">
    <lv-alert lvType="info">
        {{'protection_manual_path_tip_label' | i18n}}
    </lv-alert>
    <lv-form-item>
        <lv-form-label>
            {{'protection_path_mode_label' | i18n}}
        </lv-form-label>
        <lv-form-control>
            <lv-radio-group [(ngModel)]="pathMode" [lvGroupName]="'group'" (ngModelChange)="pathModeChange()">
                <lv-group [lvGutter]="'20px'">
                    <lv-radio [lvValue]="modeMap.fromTree">
                        {{ 'protection_path_from_tree_label' | i18n }}
                    </lv-radio>
                    <lv-radio [lvValue]="modeMap.fromTag">
                        {{ 'protection_path_from_input_label' | i18n }}
                    </lv-radio>
                </lv-group>
            </lv-radio-group>
        </lv-form-control>
    </lv-form-item>
    <lv-form-item *ngIf="pathMode === modeMap.fromTag">
        <lv-form-label lvRequired>
            {{'protection_path_from_input_title_label' | i18n}}
            <i lv-icon="aui-icon-help" lv-tooltip="{{'protection_vm_path_placeholder_tip_label' | i18n}}"
                lvColorState='true'></i>
        </lv-form-label>
        <lv-form-control>
            <aui-manual-input-path [rowCopy]="copy" (pathChange)="pathChange($event)"></aui-manual-input-path>
        </lv-form-control>
    </lv-form-item>
</lv-form>
<div class="tree-table-container" *ngIf="pathMode === modeMap.fromTree">
    <div class="header-tab">
        <lv-radio-group [(ngModel)]="pathView" [lvGroupName]="'path'" (ngModelChange)="tabChange()">
            <lv-group lvGutter='14px'>
                <lv-radio [lvViewType]="'custom'" [lvValue]="'all'">
                    <div>
                        {{'protection_sla_optional_tooltip_step_label' | i18n}}
                        <span class="num-tag" [ngClass]="{'tag-light': pathView === 'all'}">{{total}}</span>
                    </div>
                </lv-radio>
                <div class="dash-line"></div>
                <lv-radio [lvViewType]="'custom'" [lvValue]="'selected'">
                    <div>
                        {{'common_selected_simple_label' | i18n}}
                        <span class="num-tag"
                            [ngClass]="{'tag-light': pathView === 'selected'}">{{selectedTotal}}</span>
                    </div>
                </lv-radio>
            </lv-group>
        </lv-radio-group>
    </div>
    <lv-group lvGutter='14px' [lvColumns]='["auto", "270px"]' class="search-path-container">
        <ng-container *ngIf="isPathSearchFlag; else elseTemplate">
            <input #input lv-input [(ngModel)]="currentPath" (keydown.enter)="pathSearch()" (blur)="pathSearch()"
                [attr.autofocus]="autofocus" />
        </ng-container>
        <ng-template #elseTemplate>
            <div class="bread-crumb-path" (click)="pathClick($event)">
                <lv-breadcrumb [lvItems]="filePathItems" class="breadcrumb"></lv-breadcrumb>
            </div>
        </ng-template>
        <div class="search-name">
            <lv-search (lvSearch)="searchName($event)" lvPlaceHolder="{{'common_name_label' | i18n}}"
                [(ngModel)]="searcKey"></lv-search>
        </div>
    </lv-group>
    <lv-group class="tree-table" [lvColumns]='["270px", "auto"]'>
        <div class="tree-container">
            <lv-tree #tree lvCompareWith="absolutePath" lvSelectionAssociate="false" [lvData]="treeData"
                (lvExpandedChange)="expandedChange($event)" lvSelectionMode="single" [(lvSelection)]="selectionTree"
                (lvCheck)="pathNodeCheck($event)" [lvBeforeSelected]="beforeSelected" lvShowContentIcon
                [lvNodeTemplate]='nodeTpl' style="width: auto;"></lv-tree>
            <ng-template #nodeTpl let-item>
                <div style="width: 160px;" lv-overflow>
                    <span *ngIf="!item.isMoreBtn">
                        <i lv-icon="{{item.contentToggleIcon}}"></i>
                        {{item.label}}
                    </span>
                </div>
                <span class="aui-link" *ngIf="item.isMoreBtn"
                    (click)="clickMoreFile($event, item)">{{item.label}}</span>
            </ng-template>
        </div>
        <div class="table-container">
            <ng-container *ngIf="pathView === 'all'; else elseTableTemplate">
                <lv-pro-table #dataTable [config]="tableConfig" [data]="tableData"></lv-pro-table>
            </ng-container>
            <ng-template #elseTableTemplate>
                <lv-pro-table #dataSelectTable [config]="selectTableConfig" [data]="selectTableData"></lv-pro-table>
            </ng-template>
        </div>
    </lv-group>
</div>

<ng-template #fileTpl let-item>
    <span lv-overflow>
        <i lv-icon="{{ item.contentToggleIcon }}" [lvColorState]="true"></i>
        {{ item.name }}
    </span>
</ng-template>

<ng-template #sizeTpl let-item>
    <!-- 文件夹或者链接文件不展示大小 -->
    <span lv-overflow *ngIf="!_includes([restoreFileType.Directory, restoreFileType.Link], item.type)">
        {{item.size | capacityCalculateLabel: '1.1-3':unitconst.BYTE:true}}
    </span>
</ng-template>

<ng-template #optTpl let-item>
    <lv-group class="opt-row">
        <span lv-overflow>
            {{item.modifyTime}}
        </span>
        <i lv-icon="lv-icon-close" [lvColorState]="true" (click)="deleteNode(item)"></i>
    </lv-group>
</ng-template>